package com.jintoufs.web.action.sys;

import com.baidu.ueditor.ActionEnter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Controller
public class UeditorController {
    @RequestMapping("/images/upload")
    public void config(HttpServletRequest request,
                       HttpServletResponse response, String action) {
//        response.setContentType("application/json;text/plain");
        // config.json配置文件和图片上传位置，都默认为“网站根目录”
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        rootPath +="/WEB-INF/classes/";
//        Object uploadRootPath;
////自己设置的目录
//            uploadRootPath = null;
//        if (uploadRootPath != null) {
//            rootPath = uploadRootPath.toString();
//        }

        try {
            String exec = new ActionEnter(request, rootPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
